#include<Windows.h>
/*
  HANDLE WINAPI CreateFile(
  __in      LPCTSTR lpFileName,
  __in      DWORD dwDesiredAccess, //ENERIC_READ, GENERIC_WRITE, or both (GENERIC_READ | GENERIC_WRITE). 
  __in      DWORD dwShareMode,
  __in_opt  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  __in      DWORD dwCreationDisposition,//CREATE_ALWAYS,CREATE_NEW,OPEN_ALWAYS,OPEN_EXISTING,TRUNCATE_EXISTING
  __in      DWORD dwFlagsAndAttributes,
  __in_opt  HANDLE hTemplateFile
  );
*/

hDevice = CreateFile( "\\\\.\\IoctlTest",
                      GENERIC_READ | GENERIC_WRITE,
                      0,
                      NULL,
                      CREATE_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL,
                      NULL);

if ( hDevice == INVALID_HANDLE_VALUE ){
  printf ( "Error: CreatFile Failed : %d\n", GetLastError());
  return;
 }

HANDLE hIn, hOut;
DWORD nIn, nOut;
CHAR Buffer [BUF_SIZE];
if (argc != 3) {
  printf ("Usage: cp file1 file2\n");
  return 1;
 }
hIn = CreateFile (argv [1], GENERIC_READ, 0, NULL, OPEN_EXISTING,
                  FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hIn == INVALID_HANDLE_VALUE) {
  printf ("Cannot open input file. Error: %x\n", GetLastError ());
  return 2;
 }
hOut = CreateFile (argv [2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
                   FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hOut == INVALID_HANDLE_VALUE) {
  printf ("Cannot open output file. Error: %x\n", GetLastError ());
  return 3;
 }

//FsLow = GetFileSize (hIn, NULL);
//SetFilePointer (hOut, FsLow, NULL, FILE_BEGIN);
//SetEndOfFile (hOut);

/*  Set the output file size. */

while (ReadFile (hIn, Buffer, BUF_SIZE, &nIn, NULL) && nIn > 0) {
  WriteFile (hOut, Buffer, nIn, &nOut, NULL);
  if (nIn != nOut) {
    printf ("Fatal write error: %x\n", GetLastError ());
    return 4;
  }
 }
CloseHandle (hIn);
CloseHandle (hOut);
return 0;
